package com.lys.eduservice.controller;


import com.lys.commonutils.R;
import com.lys.eduservice.entity.EduChapter;
import com.lys.eduservice.entity.chapter.chapterVo;
import com.lys.eduservice.service.EduChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author Lyyyys
 * @since 2021-04-30
 */
@Api(description="章节管理")
@RestController
@RequestMapping("/eduservice/chapter")
@CrossOrigin
public class EduChapterController {

    @Autowired
    private EduChapterService eduChapterService;

    @ApiOperation(value = "根据ID查询课程")
    @GetMapping("getChapterVideo/{id}")
    public R getChapterVideo(@PathVariable String id){
        List<chapterVo> list = eduChapterService.getChapterVideo(id);
        return R.ok().data("list",list);
    }

    //添加章节的接口
    @ApiOperation(value = "添加章节信息")
    @PostMapping("addChapter")
    public R addChapter(@RequestBody EduChapter eduChapter){
        eduChapterService.save(eduChapter);
        return R.ok();
    }

    //查询章节信息
    @ApiOperation(value = "Id查询章节信息")
    @GetMapping("getChapter/{id}")
    public R getChapter(@PathVariable String id){
        EduChapter chapter = eduChapterService.getById(id);
        return R.ok().data("chapter",chapter);
    }

    //修改章节信息
    @ApiOperation(value = "修改章节信息")
    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody EduChapter eduChapter){
        eduChapterService.updateById(eduChapter);
        return R.ok();
    }

    //删除
    @DeleteMapping("{id}")
    public R deleteChapter(@PathVariable String id){
        boolean flag = eduChapterService.deleteChapter(id);
        return flag == true ? R.ok(): R.error();
    }
}

